package com.cqw.controller;

import com.cqw.common.BaseResponse;
import com.cqw.service.FileService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @Author: caoqingwen
 * @CreateTime: 2021-05-06 16:13
 * @Description: 文件上传下载
 */
@RestController
@RequestMapping
@Slf4j
@Api(tags = "文件上传下载")
public class FileController {


    @Resource
    private FileService fileService;


    @PostMapping("upload")
    public BaseResponse upload(MultipartFile file) {
        //上传并返回url
        String url = null;
        try {
            url = fileService.uploadFile(file);
            return BaseResponse.success(url);
        } catch (Exception e) {
            log.error("文件上传失败", e);
            return BaseResponse.error(e.getMessage());
        }
    }


}
